#include "World.h"



void World::update(float dt)
{
    if (objects.size() < 1)return;

    for (auto& body : objects)
    {
        body->update(dt,this->renderer);
        
        
    }
    
    QuadTree tree;
    tree.boundary = Rect(vec2(0, 0), vec2(800, 600));
    tree.world = this;
    tree.root = &tree;
    for (auto obj : objects)
    {
        tree.insert(obj);
    }
    tree.update();

    auto a=unique(colideinfo.begin(), colideinfo.end());
    colideinfo.erase(a, colideinfo.end());
    for (auto& info : colideinfo)
    {
        info.generate();
    }
    colideinfo.clear();
    
        
    

    
    

}

void World::addColideInfo(Object* a, Object* b)
{
    ColideInfo info(a, b);
    colideinfo.push_back(info);
}

void World::addObject(Object* object)
{
    objects.push_back(object);


    
}
